<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class gs_mod extends CI_Model
{
	public function __construct()
	{
		parent::__construct();
		$this->load->helper('url');
		$this->load->model('Customer_mod','customer');
	}

	function Insertgs($dao)
	{
		if(is_array($dao))
		{
			return $this->db->insert('tms_gs',$dao);
		}
	}
	
	function getgsList()
	{
		$sql = "SELECT * FROM tms_gs order by id desc";
		$result = $this->db->query($sql);
	
		return $result->result_array();
		//retrn "guaiguaidejiahuo";
	}
	
	function getgsinfo($gsid)
	{
		$gsid = intval($gsid);
		
		$sql = "SELECT * FROM tms_gs WHERE `id`=$gsid";
		$result = $this->db->query($sql);
		
		return $result->result();
	}
	
	function Repeatcheck($key,$value)
	{
		$sql = "SELECT * FROM tms_gs WHERE `$key` = '$value'";
		
		$query = $this->db->query($sql);
		$result = $query->result();
		
		if(!empty($result))
		{
			return 0;
		}else{
			return 1;
		}
		
	}
	
	function getCustomerList()
	{
		$sql = "SELECT * FROM tms_customer";
		$query = $this->db->query($sql);
		return $query->result_array();
	}
	
	function getgsListallTag($tags)
	{
		$sql = "SELECT name FROM tms_gs WHERE `name` LIKE '%$tags%'";
		$query = $this->db->query($sql);
		
		foreach($query->result_array() AS $ln)
		{
			$arr[] = $ln['name'];
		}
		
		return $arr;
	}
	
	function getgsIdByName($gsname)
	{
		$sql = "SELECT id FROM tms_gs WHERE `name` = '$gsname'";
		$query = $this->db->query($sql);
		
		$arr = $query->row_array();
		
		return $arr['id'];
	}
	
	function searchLink($gsname)
	{
		$sql = "SELECT * FROM tms_gs WHERE `name` LIKE '%$gsname%'";
		$query = $this->db->query($sql);
		
		return $arr = $query->result_array();
	}
	
	function checkgsRepeat($gsname)
	{
		$sql = "SELECT * FROM tms_gs WHERE `name` LIKE '$gsname'";
		$query = $this->db->query($sql);
		$re = $query->result_array();
		return empty($re);
	}
}

?>